home *** CD-ROM | disk | FTP | other *** search
- /* filedate.c (originally utime.c), by Paul Wells. Modified by John Bush
- * and others (see also sendpkt() comments, below); NewtWare SetFileDate()
- * clone cheaply ripped off from utime().
- */
-
- /* HISTORY/CHANGES
- * Created: 2 Sep 92, by Cave "Greg Roelofs" Newt
- * Incorporated into UnZip 5.1 -- J.Bush, 6 Sep 92:
- * Interlude "FileDate()" defined, which calls or redefines
- * SetFileDate() depending upon AMIGADOS2 definition.
- */
-
- /* DESCRIPTION
- * This routine chooses between 2 methods to set the file date on AMIGA.
- * Since AmigaDOS 2.x came out, SetFileDate() was available in ROM (v.36
- * and higher). Under AmigaDOS 1.3.x (less than v.36 ROM), SetFileDate()
- * must be accomplished by constructing a message packet and sending it
- * to the file system handler of the file to be stamped.
- *
- * If AMIGADOS2 is defined, then ROM version of SetFileDate() is called.
- * If AMIGADOS2 is NOT defined, then substitute "equivalent" code prevails.
- * If AMIGA is undefined, don't compile (error... AMIGADOS2 probably defined
- * on non-Amiga platform).
- */
-
- #include <string.h>
- #include <time.h>
- #include <errno.h>
-
- #include <exec/types.h>
- #include <exec/memory.h>
- #include <libraries/dos.h>
- #include <libraries/dosextens.h>
- #include <proto/exec.h>
- #include <proto/dos.h>
-
- LONG FileDate(char *filename, struct DateStamp *pDate);
-
- extern int _OSERR;
-
- #ifndef SUCCESS
- # define SUCCESS (-1L)
- # define FAILURE 0L
- #endif
-
-
- /* ------------------------------------------------------------------- */
- #ifdef AMIGADOS2
- /* ------------------------------------------------------------------- */
-
- LONG SetFileDate(char *filename, struct DateStamp *pDate);
-
- LONG FileDate(filename, pDate)
- char *filename;
- struct DateStamp *pDate;
- {
- return (SetFileDate(filename,pDate)); /* native routine at 2.0+ */
- }
-
- /* ------------------------------------------------------------------- */
- #else /* !AMIGADOS2 */
- #ifdef AMIGA
- /* ------------------------------------------------------------------- */
-
- LONG sendpkt(struct MsgPort *pid, LONG action, LONG *args, LONG nargs);
-
- LONG FileDate(filename, pDate)
- char *filename;
- struct DateStamp *pDate;
- {
- struct MsgPort *taskport;
- struct FileLock *dirlock, *lock;
- struct FileInfoBlock *fib;
- LONG argv[4];
- UBYTE *ptr;
- long ret;
-
-
- if( !(taskport = (struct MsgPort *)DeviceProc(filename)) )
- {
- errno = ESRCH; /* no such process */
- _OSERR = IoErr();
- return FAILURE;
- }
-
- if( !(lock = (struct FileLock *)Lock(filename,SHARED_LOCK)) )
- {
- errno = ENOENT; /* no such file */
- _OSERR = IoErr();
- return FAILURE;
- }
-
- if( !(fib = (struct FileInfoBlock *)AllocMem(
- (long)sizeof(struct FileInfoBlock),MEMF_PUBLIC|MEMF_CLEAR)) )
- {
- errno = ENOMEM; /* insufficient memory */
- UnLock((BPTR)lock);
- return FAILURE;
- }
-
- if( Examine((BPTR)lock,fib)==FAILURE )
- {
- errno = EOSERR; /* operating system error */
- _OSERR = IoErr();
- UnLock((BPTR)lock);
- FreeMem((char *)fib,(long)sizeof(*fib));
- return FAILURE;
- }
-
- dirlock = (struct FileLock *)ParentDir((BPTR)lock);
- ptr = (UBYTE *)AllocMem(64L,MEMF_PUBLIC);
- strcpy((ptr+1),fib->fib_FileName);
- *ptr = strlen(fib->fib_FileName);
- FreeMem((char *)fib,(long)sizeof(*fib));
- UnLock((BPTR)lock);
-
- /* now fill in argument array */
-
- argv[0] = NULL;
- argv[1] = (LONG)dirlock;
- argv[2] = (LONG)&ptr[0] >> 2;
- argv[3] = (LONG)pDate;
-
- errno = ret = sendpkt(taskport,34L,argv,4L);
-
- FreeMem(ptr,64L);
- UnLock((BPTR)dirlock);
-
- return SUCCESS;
-
- } /* FileDate() */
-
- /* sendpkt.c
- * by A. Finkel, P. Lindsay, C. Sheppner
- * returns Res1 of the reply packet
- */
- /*
- #include <exec/types.h>
- #include <exec/memory.h>
- #include <libraries/dos.h>
- #include <libraries/dosextens.h>
- #include <proto/exec.h>
- #include <proto/dos.h>
- */
-
- LONG sendpkt(pid,action,args,nargs)
- struct MsgPort *pid; /* process identifier (handler message port) */
- LONG action, /* packet type (desired action) */
- *args, /* a pointer to argument list */
- nargs; /* number of arguments in list */
- {
-
- struct MsgPort *replyport;
- struct StandardPacket *packet;
- LONG count, *pargs, res1;
-
- replyport = (struct MsgPort *)CreatePort(0L,0L);
- if( !replyport ) return(NULL);
-
- packet = (struct StandardPacket *)AllocMem(
- (long)sizeof(struct StandardPacket),MEMF_PUBLIC|MEMF_CLEAR);
- if( !packet )
- {
- DeletePort(replyport);
- return(NULL);
- }
-
- packet->sp_Msg.mn_Node.ln_Name = (char *)&(packet->sp_Pkt);
- packet->sp_Pkt.dp_Link = &(packet->sp_Msg);
- packet->sp_Pkt.dp_Port = replyport;
- packet->sp_Pkt.dp_Type = action;
-
- /* copy the args into the packet */
- pargs = &(packet->sp_Pkt.dp_Arg1); /* address of 1st argument */
- for( count=0; count<nargs; count++ )
- pargs[count] = args[count];
-
- PutMsg(pid,(struct Message *)packet); /* send packet */
-
- WaitPort(replyport);
- GetMsg(replyport);
-
- res1 = packet->sp_Pkt.dp_Res1;
-
- FreeMem((char *)packet,(long)sizeof(*packet));
- DeletePort(replyport);
-
- return(res1);
-
- } /* sendpkt() */
-
- #endif /* AMIGA */
- #endif /* ?AMIGADOS2 */
-